home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / KMShaders / KMStrata.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  2.6 KB  |  85 lines

  1. /* modified by wave to KMStrata for name space protection... */
  2. /*
  3.  * strata.sl -- surface shader for sedimentary rock strata
  4.  *
  5.  * DESCRIPTION:
  6.  *    Makes sedimentary rock strata, useful for rendering landscapes.
  7.  *
  8.  * PARAMETERS:
  9.  *    Ka, Kd - the usual meaning
  10.  *    txtscale - overall scaling factor for the texture
  11.  *    zscale - scaling for the thickness of the layers
  12.  *    turbscale - how turbulent the layers are
  13.  *    offset - z offset for the pattern
  14.  *    octaves - number of octaves of noise to sum for the turbulence
  15.  *
  16.  * ANTIALIASING:
  17.  *    None.
  18.  *
  19.  *
  20.  * AUTHOR:
  21.  *    C language version by F. Kenton Musgrave
  22.  *    Translation to Shading Language by Larry Gritz.
  23.  *
  24.  * REFERENCES:
  25.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  26.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  27.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  28.  *
  29.  * HISTORY:
  30.  *    ??? - original C language version by Ken Musgrave
  31.  *    Apr 94 - translation to Shading Language by L. Gritz
  32.  *
  33.  * this file last updated 18 Apr 1994
  34.  */
  35.  
  36. #define snoise(Pt) (2*noise(Pt) - 1)
  37.  
  38.  
  39. surface
  40. KMStrata (float Ka = 0.5, Kd = 1;
  41.       float txtscale = 1;
  42.       float zscale = 2;
  43.       float turbscale = 0.1;
  44.       float offset = 0;
  45.       float octaves = 8;)
  46. {
  47.   color Ct;
  48.   point PP;
  49.   float cmap;
  50.   float turb, i, freq;
  51.  
  52.   PP = txtscale * transform ("shader", P);
  53.  
  54.   turb = 0;  freq = 1;
  55.   for (i = 0;  i < octaves;  i += 1) {
  56.       turb += abs (snoise(PP*freq) / freq);
  57.       freq *= 2;
  58.     }
  59.  
  60.   cmap = zscale * zcomp(PP) + turbscale * turb - offset;
  61.   Ct = color spline (mod (cmap, 1),
  62.              color (166,131,70), color (166,131,70), 
  63.              color (204, 178, 127), color (184, 153, 97), 
  64.              color (140, 114, 51),  color (159, 123, 60), 
  65.              color (204, 178, 127), color (230, 180, 80), 
  66.              color (192, 164, 110), color (172, 139, 80), 
  67.              color (102, 76, 25),   color (166, 131, 70), 
  68.              color (201, 175, 124), color (181, 150, 94), 
  69.              color (161, 125, 64),  color (177, 145, 87), 
  70.              color (170, 136, 77),  color (197, 170, 117), 
  71.              color (180, 100, 50),  color (175, 142, 84), 
  72.              color (197, 170, 117), color (177, 145, 87), 
  73.              color (170, 136, 77),  color (186, 156, 100), 
  74.              color (166, 131, 70),  color (188, 159, 104), 
  75.              color (168, 134, 74),  color (159, 123, 60), 
  76.              color (195, 167, 114), color (175, 142, 84), 
  77.              color (161, 125, 64),  color (197, 170, 117), 
  78.              color (177, 145, 87), color (177, 145, 87)
  79.              ) / 255;
  80.  
  81.   /* Shade like matte, but with color scaled by cloudcolor and opacity */
  82.   Oi = 1;
  83.   Ci = Cs * Ct * (Ka * ambient() + Kd * diffuse(faceforward(normalize(N),I)));
  84. }
  85.